import maya.cmds as cmds

def toggle_nurbs_visibility():
    # Find the panel that currently has focus
    active_panel = cmds.getPanel(withFocus=True)
    
    # Ensure the panel is a 3D viewport (modelPanel)
    if cmds.getPanel(typeOf=active_panel) == 'modelPanel':
        # Check current visibility state of NURBS Curves
        current_state = cmds.modelEditor(active_panel, query=True, nurbsCurves=True)
        
        # Invert the state
        new_state = not current_state
        cmds.modelEditor(active_panel, edit=True, nurbsCurves=new_state)
        
        print(f"NURBS Curves visibility set to: {new_state}")
    else:
        cmds.warning("Please click into a 3D viewport first.")

toggle_nurbs_visibility()